home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / develop / develop issue 23 / develop issue 23 code / projectdrag 1.1b8.sea / ProjectDrag 1.1b8 / Sources / ProjectDrag Sources / Update.c / Update.c
Encoding:
C/C++ Source or Header  |  1995-07-24  |  4.8 KB  |  206 lines  |  [TEXT/MPS ]

  1. /* Update.c: Update applet for ProjectDrag.
  2.  *
  3.  * A set of applets for drag and drop source control by Tim Maroney.
  4.  * See develop, issue 23 for details.
  5.  *
  6.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  7.  * and using the MoreFiles utilities by Jim Luther.
  8.  *
  9.  * This software is free, but don't modify and redistribute it without
  10.  * changing the status window to indicate your name and your changes!
  11.  */
  12.  
  13.  
  14. #include <Errors.h>
  15.  
  16. #include "DSUserProcs.h"
  17. #include "SourceServer.h"
  18. #include "PDDialogs.h"
  19. #include "MoreFilesExtras.h"
  20. #include "TasksAndErrors.h"
  21. #include "FileCancel.h"
  22.  
  23.  
  24. void UpdateFile(FSSpec *file, Boolean doingFolder);
  25. OSErr UpdateFolder(short vRefNum, long folderID,
  26.                   void (*doFile)(FSSpec *file, Boolean doingFolder));
  27.  
  28.  
  29. /* This routine is called for each file passed in the ODOC event. */
  30.  
  31. pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
  32. {
  33. #pragma unused ( opening )
  34. #pragma unused ( userDataHandle )
  35.  
  36.     ProcessFileOrFolder(myFSSPtr, UpdateFile, UpdateFolder);
  37. }
  38.  
  39.  
  40. void UpdateFile(FSSpec *file, Boolean doingFolder)
  41. {
  42. #pragma unused ( doingFolder )
  43.  
  44.     Str63 userName;
  45.     Str15 nickname;
  46.     OSErr err;
  47.     CKIDHandle theCKID;
  48.     AEDesc command;
  49.     Str255 projectName;
  50.     
  51.     TaskStart(2001, 1, file->name, NULL, NULL, NULL);
  52.     
  53.     /* find the user name and initials */
  54.     err = GetUserSettings(userName, nickname, false);
  55.     if (err != noErr)
  56.     {
  57.         gDone = true;
  58.         return;
  59.     }
  60.     
  61.     /* get the CKID */
  62.     err = ExtractCKID(file, &theCKID);
  63.     if (err != noErr)
  64.     {
  65.         RaiseErrorString(kProjectDragStrings, kCantGetCKID, file->name,
  66.                          NULL, NULL, NULL);
  67.         return;
  68.     }
  69.     
  70.     /* is the file already checked out or MRO? */
  71.     if ((*theCKID)->modifyReadOnly || (*theCKID)->writeable)
  72.     {
  73.         /* confirm the discard */
  74.         if (!ResTextYesNo(kProjectDragStrings, kConfirmDiscardChanges, file->name, NULL, NULL, NULL))
  75.         {
  76.             DisposeHandle((Handle)theCKID);
  77.             RaiseErrorNumber(userCanceledErr);
  78.             return;
  79.         }
  80.         
  81.         err = FileCancel(file, theCKID);
  82.         DisposeHandle((Handle)theCKID);
  83.     }
  84.     else
  85.     {
  86.         /* not checked out for modify -- create a CheckOut command for SourceServer
  87.          * CheckOut -d <dir> -project <project> <file>
  88.          */
  89.  
  90.         /* mount the project */
  91.         err = MountProjectFromCKID(theCKID, projectName);
  92.         DisposeHandle((Handle)theCKID);
  93.         if (err != noErr) return;
  94.     
  95.         err = CreateCommand(&command, "CheckOut");
  96.         if (err == noErr)
  97.             err = AddDirArg(&command, file->vRefNum, file->parID);
  98.         if (err == noErr)
  99.             err = AddProjectArg(&command, projectName);
  100.         if (err == noErr)
  101.             err = AddPStringArg(&command, file->name);
  102.         if (err != noErr)
  103.         {
  104.             AEDisposeDesc(&command);
  105.             RaiseErrorNumber(err);
  106.             return;
  107.         }
  108.     
  109.         /* send the command to SourceServer */
  110.         err = SendCommand(&command);
  111.     }
  112.     
  113.     if (err == noErr) TaskDone();
  114. }
  115.  
  116.  
  117. OSErr UpdateFolder(short vRefNum, long folderID,
  118.                   void (*doFile)(FSSpec *file, Boolean doingFolder))
  119. {
  120. #pragma unused ( doFile )
  121.  
  122.     Str63 userName;
  123.     Str15 nickname;
  124.     OSErr err;
  125.     AEDesc command;
  126.     Str255 projectName;
  127.     
  128.     /* put the folder name in the status window */
  129.     {
  130.         Str31 folderName;
  131.         err = GetDirName(vRefNum, folderID, folderName);
  132.         if (err != noErr) return err;
  133.         TaskStart(2001, 1, folderName, NULL, NULL, NULL);
  134.     }
  135.     
  136.     /* find the user name and initials */
  137.     err = GetUserSettings(userName, nickname, false);
  138.     if (err != noErr)
  139.     {
  140.         gDone = true;
  141.         return err;
  142.     }
  143.     
  144.     /* mount the project */
  145.     err = MountProjectFromFolder(vRefNum, folderID, projectName);
  146.     if (err != noErr) return err;
  147.     
  148.     /* create a CheckOutDir -r command for SourceServer
  149.      * CheckOut -r -project <project> <dir>
  150.      */
  151.     err = CreateCommand(&command, "CheckOutDir");
  152.     if (err == noErr)
  153.         err = AddCStringArg(&command, "-r");
  154.     if (err == noErr)
  155.         err = AddProjectArg(&command, projectName);
  156.     if (err == noErr)
  157.     {
  158.         FSSpec dirSpec;
  159.         dirSpec.vRefNum = vRefNum;
  160.         dirSpec.parID = folderID;
  161.         dirSpec.name[0] = 0;
  162.         err = AddFileNameArg(&command, &dirSpec);
  163.     }
  164.     if (err != noErr)
  165.     {
  166.         AEDisposeDesc(&command);
  167.         return RaiseErrorNumber(err);
  168.     }
  169.     
  170.     /* send the command to SourceServer */
  171.     err = SendCommand(&command);
  172.     if (err != noErr) return err;
  173.     
  174.     /* create a CheckOut -newer -deleteObsolete -r command for SourceServer
  175.      * CheckOut -newer -deleteObsolete -r -project <project>
  176.      */
  177.     err = CreateCommand(&command, "CheckOut");
  178.     if (err == noErr)
  179.         err = AddCStringArg(&command, "-newer");
  180.     if (err == noErr)
  181.         err = AddCStringArg(&command, "-deleteObsolete");
  182.     if (err == noErr)
  183.         err = AddCStringArg(&command, "-r");
  184.     if (err == noErr)
  185.         err = AddProjectArg(&command, projectName);
  186.     if (err != noErr)
  187.     {
  188.         AEDisposeDesc(&command);
  189.         return RaiseErrorNumber(err);
  190.     }
  191.     
  192.     /* send the command to SourceServer */
  193.     err = SendCommand(&command);
  194.     if (err == noErr)
  195.         TaskDone();
  196.     return err;
  197. }
  198.  
  199. void DoFileMenu(short itemID)
  200. {
  201.     if ( itemID == 1 )
  202.         SelectFile();        // call file selection userProc
  203.     else
  204.         SendQuitToSelf();    // send self a 'quit' event
  205. }
  206.